<template>
    <el-cascader
        style="width: 100%"
        :size="mySize"
        v-bind="allAttrs"
		placeholder="请选择所属行政区划"
		v-model="value"
		:props="{ checkStrictly: true, emitPath: false,value:'key',label:'title',children:'children',disabled:'disabled',leaf:'isLeaf' }"
		:options="state.areaCodeSelectTreeData"
        :clearable="clearable"
    ></el-cascader>
</template>
<script lang="ts" setup>
import { itemProps, itemController } from '../lib/mapController';
const props = defineProps({
	modelValue: [String],
    ...itemProps, // 基础属性
    permissionFlag: {
		type: Boolean,
		default() {
			return true;
		},
	},
	defaultFlag: {
		type: Boolean,
		default() {
			return true;
		},
	},
    areaCode: {
		type: String,
		default() {
			return "";
		},
	},
    orgTypeList: {
		type: Array,
		default() {
			return [];
		},
	},
})
const emit = defineEmits(['update:modelValue']);
const attrs = useAttrs();
const allAttrs = computed(() => {
	return Object.assign(props.extend, attrs);
});
const state = reactive({
    mySize: allAttrs.value.size,
	areaCodeSelectTreeData: [],
})
const { value,globalSize } = itemController(props, allAttrs.value, emit);

function getAreaCodeData() {
	setTimeout(() => {
		$api.common.send.post('dict0026', {permissionFlag:props.permissionFlag,parentId:props.areaCode,orgTypeList:props.orgTypeList}).then((res) => {
			state.areaCodeSelectTreeData = res.result||[];
			if(state.areaCodeSelectTreeData.length==1){
				if(props.defaultFlag&&!value.value){
					value.value=state.areaCodeSelectTreeData[0].key
				}
			}
		});
	}, 20);
}
onMounted(() => {
	getAreaCodeData();
});
// 初始化
globalSize(state);
const { mySize } = toRefs(state);
</script>